package com.net.xpay.core.validator;



import com.google.common.base.Strings;
import com.net.common.exception.BusinessException;
import com.net.xpay.core.constant.PoseidonErrorCode;
import com.net.xpay.core.model.SafePayBookAccountSubmitBusinessAuthModel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 企业实名认证参数验证
 */
@Slf4j
@Component
public class SafePayBookAccountSubmitBusinessAuthValidator {

    public void validateSafePayBookAccountSubmitBusinessAuth(SafePayBookAccountSubmitBusinessAuthModel model){
        if (Strings.isNullOrEmpty(model.getAlipayNickName())){
            throw new BusinessException(PoseidonErrorCode.PARAMETER_ILLEGAL,"企业支付宝不可为空");
        }
        if (Strings.isNullOrEmpty(model.getBusinessName())){
            throw new BusinessException(PoseidonErrorCode.PARAMETER_ILLEGAL,"企业名称不可为空");
        }
        if (model.getBusinessName().length() > 64){
            throw new BusinessException(PoseidonErrorCode.PARAMETER_ILLEGAL,"企业名称不能超过64个字");
        }
        if (Strings.isNullOrEmpty(model.getIdCardFront())){
            throw new BusinessException(PoseidonErrorCode.PARAMETER_ILLEGAL,"法人手持身份证正面不可为空");
        }

        if (Strings.isNullOrEmpty(model.getIdCardBack())){
            throw new BusinessException(PoseidonErrorCode.PARAMETER_ILLEGAL,"法人手持身份证反面不可为空");
        }
        if (Strings.isNullOrEmpty(model.getBizLicense())) {
            throw new BusinessException(PoseidonErrorCode.PARAMETER_ILLEGAL,"营业执照不能为空");
        }
        if (Strings.isNullOrEmpty(model.getBusinessLicense())){
            throw new BusinessException(PoseidonErrorCode.PARAMETER_ILLEGAL,"法人手持营业执照不可为空");
        }
        List<String> officeImages = model.getOfficeImages();
        if (officeImages == null){
            throw new BusinessException(PoseidonErrorCode.PARAMETER_ILLEGAL,"办公室图片不可为空");
        }
        if (officeImages.size() < 3){
            throw new BusinessException(PoseidonErrorCode.PARAMETER_ILLEGAL,"办公室图片不可以少于3张");
        }
        if (Strings.isNullOrEmpty(model.getBizSceneDesc())){
            throw new BusinessException(PoseidonErrorCode.PARAMETER_ILLEGAL,"商务业务说明不能为空");
        }
        if (Strings.isNullOrEmpty(model.getMerchantCommitment())){
            throw new BusinessException(PoseidonErrorCode.PARAMETER_ILLEGAL,"商户承诺书不能为空");
        }
    }
}
